﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;

namespace Nardax.Data.Configuration
{
    public class DatabaseConnectionPolicyElement : ConfigurationElement
    {
        private const string NameProperty = "name";
        private const string DefaultCommandTimeoutProperty = "defaultCommandTimeout";
        private const string BatchSizeProperty = "defaultBatchSize";
        private const string ConnectionStringProperty = "connectionString";

        /// <summary>
        /// Gets or sets the unique name of the retry policy under which it is registered and referenced in the application configuration.
        /// </summary>
        [ConfigurationProperty(NameProperty, IsRequired = true)]
        public string Name
        {
            get { return Convert.ToString(base[NameProperty]); }
            set { base[NameProperty] = value; }
        } /// <summary> 
        /// Gets or sets the default value for the CommandTimeout setting on command that are generated 
        /// using the <see cref="T:Nardax.Data.SqlDatabase"/> class. 
        /// </summary> 
        [ConfigurationProperty(DefaultCommandTimeoutProperty, DefaultValue = 30)]
        public int DefaultCommandTimeout
        {
            get { return (int)this[DefaultCommandTimeoutProperty]; }
            set { this[DefaultCommandTimeoutProperty] = value; }
        }

        /// <summary> 
        /// Gets or sets the default value for the BatchSize setting on SqlBulkCopy operations that are generated 
        /// using the <see cref="T:Nardax.Data.SqlDatabase"/> class. 
        /// </summary> 
        [ConfigurationProperty(BatchSizeProperty, DefaultValue = 0)]
        public int DefaultBatchSize
        {
            get { return (int)this[BatchSizeProperty]; }
            set { this[BatchSizeProperty] = value; }
        }

        /// <summary> 
        /// Gets or sets the default connection string that is used when CreateDatabase() is called on 
        /// <see cref="T:Nardax.Data.SqlDatabase"/>. 
        /// </summary> 
        [ConfigurationProperty(ConnectionStringProperty, IsRequired = true)]
        public string ConnectionString
        {
            get { return (string)this[ConnectionStringProperty]; }
            set { this[ConnectionStringProperty] = value; }
        }
    }
}
